package com.yizisu.playerlibrary.view.video_view.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.ProgressBar
import com.yizisu.playerlibrary.IYzsPlayer
import com.yizisu.playerlibrary.view.video_view.helper.IPlayerConfig
import com.yizisu.playerlibrary.view.video_view.helper.IPlayerHelper

/**
 * 倍速调节文本
 */
open class PlayerBufferingView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = android.R.attr.progressBarStyle
) : ProgressBar(
    context,
    attrs,
    defStyleAttr
), IPlayerHelper {
    override fun onAttachPlayerConfig(playerConfig: IPlayerConfig) {

    }

    override fun onDetachedPlayerConfig(playerConfig: IPlayerConfig) {
    }


    override fun isNeedPlayerListener(): Boolean {
        return true
    }

    override fun onBufferStateChange(
        isBuffering: Boolean,
        playStatus: Boolean,
        playerModel: IYzsPlayer.Model?
    ) {
        super.onBufferStateChange(isBuffering, playStatus, playerModel)
        visibility = if (isBuffering && playStatus) {
            View.VISIBLE
        } else {
            View.INVISIBLE
        }
    }

    override fun onPrepare(playerModel: IYzsPlayer.Model?) {
        super.onPrepare(playerModel)
        visibility = View.VISIBLE
    }

    override fun onError(throwable: Throwable, playerModel: IYzsPlayer.Model?) {
        super.onError(throwable, playerModel)
        visibility = View.INVISIBLE
    }
}